import 'package:get/get.dart';

import 'ly_storage.dart';

class DeviceTokenManger {
  static final DeviceTokenManger _instance = DeviceTokenManger._();

  factory DeviceTokenManger() => _instance;

  static DeviceTokenManger get instance => DeviceTokenManger();

  DeviceTokenManger._();

  // 华为token
  static final RxString _huawei = ''.obs;

  // 获取当前华为token
  static String get huawei => _huawei.value;

   Future<String> getHuaWei() async{
    if (_huawei.isEmpty) {
      _huawei.value = await LyStorage.getString(key: 'set_huawei_device_token');
    }
    return _huawei.value;
  }

  // 存储华为token
   Future<bool> setHuaWei(String huawei, {bool reset = true}) async {
    _huawei.value = huawei;
    var success = true;
    /// 存到本地
    if (reset) {
      success = await LyStorage.setString(
          key: 'set_huawei_device_token', value: huawei);
    }
    return success;
  }
}
